#include <stdio.h>

typedef struct ListNode{
    int value;
    struct ListNode *next;
}ListNode;

ListNode* New(int value) {
    ListNode* new = (ListNode*)malloc(sizeof(ListNode));
    new->value = value;
    new->next = NULL;
    return new;
}

ListNode* IfThereIsACycle(ListNode *head) {
    ListNode *slow = head;
    ListNode *fast = head;

    
    while (fast != NULL && fast->next != NULL) {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast) {
            
            ListNode *entrance = head;
            slow =slow->next;
            int time=1;//time为环上的节点个数
            while (fast!=slow) {
                slow = slow->next;
                time++;
            }
            int find =0;
            while (1){
                for (int i=0; i<time; i++) {
                    if (slow=entrance){return slow;}
                    slow=slow->next;
                }
                entrance=entrance->next;
            }
        }
    }
    return NULL; 
}


